package de.bastian.hinterleitner;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import de.hijacksoft.wyc.R;

public class WhatsNewActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_whatsnew);
		
		try {
			setTitle(getString(R.string.whatsnew).replace("$1", getPackageManager().getPackageInfo(getPackageName(), 0).versionName));
		} catch (NameNotFoundException e) {
			finish();
		}
		
		TextView text = (TextView)findViewById(R.id.news_text);
		text.setText(Html.fromHtml(toHtml(getString(R.string.news)+"[br/][br/]"+getString(R.string.impressum))));
		
		Button ok = (Button)findViewById(R.id.news_ok);
		ok.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		
		SharedPreferences sp = getSharedPreferences("values", MODE_PRIVATE);
    	try {
			sp.edit().putString("version", getPackageManager().getPackageInfo(getPackageName(), 0).versionName).commit();
		} catch (NameNotFoundException e) {
		}
	}

	private String toHtml(String string) {
		string = string.replace("[", "<");
		string = string.replace("]", ">");
		return string;
	}
	
}
